

from file_define import *

csv_reader = CSV_Reader(".\\销售数据\\2011年1月销售数据.csv")
csv_data:list[Record] = csv_reader.read_data()

json_reader = JsonReader(".\\销售数据\\2011年2月销售数据JSON.txt")
json_data:list[Record] = json_reader.read_data()


all_data:list[Record] = json_data + csv_data # 合并数据

from pymysql import Connection

connection = Connection(
    host="localhost",
    port=3306,
    user="root",
    password="123456",
    autocommit=True
)

cursor = connection.cursor()

connection.select_db("py_sql")


for record in all_data:    
    sql_cmd = f"insert into orders(order_date, order_id, money, province)"\
        f" values('{record.date}', '{record.order_id}', '{record.money}', '{record.province}')"
    cursor.execute(sql_cmd)

connection.close()


